<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style media="screen">
    </style>
</head>
<body>
    <div id="root"></div>
    <script src="../../js/react.js" charset="utf-8"></script>
    <script src="../../js/react-dom.js" charset="utf-8"></script>
    <script src="../../js/browser.min.js" charset="utf-8"></script>
    <script type="text/babel">

    class MediaQuery extends React.Component {
        constructor(props) {
            super(props);
            this.state = {type:'desktop'};
        }

        getChildContext() {
            console.log(this.state.type);
            return {type: this.state.type};
        }

        componentDidMount() {
            const checkMediaQuery = () => {
                const type = window.matchMedia("(min-width: 1025px)").matches ? 'desktop' : 'mobile';
                if (type !== this.state.type) {
                    this.setState({type});
                }
            };

            window.addEventListener('resize', checkMediaQuery);
            checkMediaQuery();
        }

        render() {
            // return null
            return <div>{this.props.children}</div>;
        }
    }

    MediaQuery.childContextTypes = {
        type: React.PropTypes.string
    };

    ReactDOM.render(
        <MediaQuery children={[1,5,6]} />,
        document.getElementById('root')
    )
    </script>
</body>
</html>
